package com.foot.travel.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.ViewGroup;
import android.webkit.WebView;

import com.foot.travel.R;
import com.foot.travel.event.NetRefreshEvent;
import com.koalac.ironman.common.module.ModuleActivity;
import com.koalac.ironman.net.MyRequest;
import com.koalac.ironman.net.ResponseCallback;
import com.koalac.ironman.net.pojo.request.Agent;
import com.koalac.ironman.net.pojo.response.AgentDetail;
import com.koalac.ironman.net.pojo.response.Response;
import com.koalac.ironman.viewhelper.ViewInject;
import com.koalac.ironman.widget.LoadingDialog;
import com.squareup.otto.Subscribe;

public class ProxyActivity extends ModuleActivity{
    
    @ViewInject(id = R.id.text)
    WebView mTextView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setBackButtonVisibility(true);
	    setNavigationTitle("代理声明");
	    init();
	}
	
	private void init() {
	    Agent agent = new Agent();
	    final LoadingDialog loadingDialog = showLoadingDialog("获取代理详情..");
	    MyRequest.request(ProxyActivity.this, agent, new ResponseCallback() {
	        
	        @Override
	        public void process(boolean result, Context context, Response data,
	    	    String msg) {
	            canceledLoadingDialog(loadingDialog);
	            if (result) {
	        	AgentDetail agentDetail = data.getObject(AgentDetail.class);
		            mTextView.loadUrl(agentDetail.getMessage());
		            setNetworkVisibility(false);
			}else {
			    setNetworkVisibility(true);
			}
	            
	        }
	    });
	}
	 @Subscribe
	    public void onRefresh(NetRefreshEvent netRefreshEvent) {
		setNetworkVisibility(false);
		init();
	    }

	@Override
	protected void initLayout(ViewGroup rootContentView) {
	    addContentView(R.layout.fragment_proxy);
	}
}
